<template>
  <!-- 摄像头列表组件 -->
  <div class="allcameramain">
    <!-- 摄像头列表 -->
    <div class="cameralistmain">
      <div class="camera-title">摄像头列表</div>
      <div class="camera-zlist">
        <div v-for="(item, index) in cameraList" :key="index" class="camera-item"
          :class="cameraId === item.cameraId ? 'beselect' : ''" @click="getcamermes(item.cameraId)">
          <i class="el-icon-video-camera"></i>
          {{ item.cameraName }}
        </div>
      </div>
    </div>
    <!-- 摄像头控制按钮 -->
    <div class="cameracontrol">
      <div class="controne">
        <div class="contro-m z-top" @click="startcontrol(0)">
          <i class="el-icon-caret-top"></i>
        </div>
        <div class="contro-m z-left" @click="startcontrol(2)">
          <i class="el-icon-caret-left"></i>
        </div>
        <div class="contro-m z-right" @click="startcontrol(3)">
          <i class="el-icon-caret-right"></i>
        </div>
        <div class="contro-m z-bottom" @click="startcontrol(1)">
          <i class="el-icon-caret-bottom"></i>
        </div>
        <div class="contro-m z-mirror" @click="mirrorcontrol()">
          <i class="el-icon-refresh-right"></i>
        </div>
      </div>
      <div class="controtwo">
        <div class="contro-left" @click="startcontrol(10)">焦距
          <i class="el-icon-plus"></i>
        </div>
        <div class="contro-right" @click="startcontrol(11)">焦距
          <i class="el-icon-minus"></i>
        </div>
      </div>
      <div class="controthree">
        <div class="greenbut" @click="startcontrol(8)">
          <i class="el-icon-zoom-in"></i> 放大
        </div>
        <div class="greenbut" @click="startcontrol(9)">
          <i class="el-icon-zoom-out"></i>缩小
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import nowpagereq from "@/api/basic-info-manage/area";
// import axios from 'axios'
export default {
  props: {
    cameralistparam: {
      type: Object,
      default: () => { }
    }
  },
  data () {
    return {
      // 当前摄像头id
      cameraId: "",
      // 当前选中摄像头的详细信息
      cameraInfoList: {},
      // 摄像头列表
      cameraList: [],
      // 网页播放地址
      cameraurl: ""
    }
  },
  watch: {
    cameralistparam (newval) {
      this.getcameralist()
    }
  },
  mounted () {

  },
  methods: {
    // 获取摄像头列表
    getcameralist () {
      let params = this.cameralistparam
      nowpagereq.getcameraList(params).then(
        res => {
          this.cameraList = res.data
          this.cameraId = res.data[0]["cameraId"]
          this.getcamermes(this.cameraId)
        }
      )
    },
    // 获取某个摄像头详细信息
    getcamermes (id) {
      this.cameraId = id
      nowpagereq.getcameramessage(id).then(
        res => {
          let data = res.data
          this.cameraInfoList = data.camera
          this.setcameraurl()
        }
      )
    },
    // 拼接摄像头地址
    setcameraurl () {
      if (this.cameraInfoList.cameraInfo.status === 1) {
        this.cameraurl = ""
        this.cameraurl = `https://open.ys7.com/ezopen/h5/iframe?url=ezopen://open.ys7.com/E67865597/1.hd.live&autoplay=1&accessToken=${this.cameraInfoList['accessToken']}`
        this.$emit("nowcameraurl", this.cameraurl)
      } else {
        this.$message.warning("摄像头不在线！请稍后重试")
        return
      }
    },
    // 开始控制
    async startcontrol (i) {
      let params = {
        cameraId: this.cameraId,
        direction: i,
        speed: 1
      }
      await nowpagereq.controlcamera(params)
      setTimeout(() => {
        this.stopcontrol()
      }, 500);
    },
    // 镜像翻转
    async mirrorcontrol () {
      let params = {
        cameraId: this.cameraId,
        direction: 2,
        speed: 1
      }
      await nowpagereq.mirrorcamera(params)
      setTimeout(() => {
        this.stopcontrol()
      }, 500);
    },
    // 停止控制
    stopcontrol () {
      let params = {
        cameraId: this.cameraId
      }
      nowpagereq.stopcamera(params).then(
        res => {
          // console.log(res)
        }
      )
    }
  }
}
</script>
<style lang="scss" scoped>
.allcameramain {
  height: 100%;
  width: 100%;
}

.cameralistmain {
  width: 100%;
  height: 30%;
  display: flex;
  flex-flow: nowrap column;
  align-items: center;
  justify-content: center;

  .camera-title {
    width: 80%;
    height: 30px;
    line-height: 30px;
    border: 1px solid #ccc;
    position: relative;
    z-index: 6;
    margin: 0 auto;
    text-align: center;
    background: #005d7b;
  }

  .camera-zlist {
    width: 100%;
    height: calc(100% - 20px);
    position: relative;
    z-index: 5;
    top: -10px;
    display: flex;
    flex-flow: nowrap column;
    align-items: center;
    justify-content: center;
    border: #fff 2px dashed;
    overflow: auto;
  }

  .camera-item {
    cursor: pointer;
    width: 80%;
    font-weight: 700;
    font-size: 20px;
    line-height: 40px;
    height: 40px;
    color: #fff;
    margin-bottom: 10px;
    border-radius: 5px;
    text-align: center;
    border: 1px solid #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .camera-item:hover {
    background-image: linear-gradient(to right, #46c357, #b3ec70, #46c357);
  }

  .beselect {
    background-image: linear-gradient(to right, #46c357, #b3ec70, #46c357);
  }
}

.cameracontrol {
  width: 100%;
  height: calc(70% - 10px);
  margin-top: 10px;

  .controne {
    width: 100%;
    height: 65%;
    background-image: url("~@/assets/camera/ctrlBg.png");
    background-repeat: no-repeat;
    background-size: 90%;
    background-position: center;
    position: relative;

    .contro-m {
      // border: #46c357 1px solid;
      position: relative;
      width: 25%;
      height: 25%;
      text-align: center;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 40px;
      cursor: pointer;
    }

    .contro-m:hover {
      font-size: 48px;
    }

    .z-top {
      top: 10%;
      left: 37%;
    }

    .z-left {
      top: 12%;
      left: 11%;
    }

    .z-right {
      top: -13%;
      left: 63%;
    }

    .z-bottom {
      top: -10%;
      left: 37%;
    }

    .z-mirror {
      top: -63%;
      left: 37%;
    }
  }

  .controtwo {
    width: 100%;
    height: 15%;
    display: flex;
    justify-content: space-around;

    .contro-left {
      width: 48%;
      height: 100%;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      // border: #46c357 1px solid;
      background-image: url("~@/assets/camera/transformLeft.png");
      background-repeat: no-repeat;
      background-size: 70%;
      background-position: center;
      padding-right: 30px;
      cursor: pointer;
      font-size: 16px;
    }

    .contro-left:hover {
      font-size: 20px;
    }

    .contro-right {
      width: 48%;
      height: 100%;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      // border: #46c357 1px solid;
      background-image: url("~@/assets/camera/transformRight.png");
      background-repeat: no-repeat;
      background-size: 70%;
      background-position: center;
      padding-left: 30px;
      cursor: pointer;
      font-size: 16px;
    }

    .contro-right:hover {
      font-size: 20px;
    }
  }

  .controthree {
    width: 100%;
    height: 17%;
    display: flex;
    justify-content: space-around;
    align-items: center;

    .greenbut {
      width: 28%;
      height: 60%;
      background-color: rgb(132, 180, 111);
      border-radius: 5px;
      text-align: center;
      display: flex;
      justify-content: center;
      align-items: center;
      font-weight: 600;
      font-size: 22px;
      cursor: pointer;
    }

    .greenbut:hover {
      font-size: 24px;
    }
  }
}</style>
